home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DMAKE38B.ARJ / DUMP.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  3KB  |  125 lines

  1. /*
  2.  * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).  
  3.  * You may copy, distribute, and use this software as long as this
  4.  * copyright statement is not removed.
  5.  */
  6. #include <stdio.h>
  7. #include "malloc.h"
  8. #include "tostring.h"
  9.  
  10. /*
  11.  * Function:    malloc_dump()
  12.  *
  13.  * Purpose:    to dump a printed copy of the malloc chain and
  14.  *        associated data elements
  15.  *
  16.  * Arguments:    fd    - file descriptor to write data to
  17.  *
  18.  * Returns:    nothing of any use
  19.  *
  20.  * Narrative:    Just print out all the junk
  21.  *
  22.  * Notes:    This function is implemented using low level calls because
  23.  *         of the likelyhood that the malloc tree is damaged when it
  24.  *        is called.  (Lots of things in the c library use malloc and
  25.  *        we don't want to get into a catch-22).
  26.  *
  27.  */
  28.  
  29. #ifndef lint
  30. static
  31. char rcs_hdr[] = "$Id: dump.c,v 1.1 1992/01/24 03:29:01 dvadura Exp $";
  32. #endif
  33.  
  34.  
  35. #define ERRSTR    "I/O Error on malloc dump file descriptor\n"
  36.  
  37. #define WRITEOUT(fd,str,len)    if( write(fd,str,(unsigned)len) != len ) \
  38.                 { \
  39.                     (void) write(2,ERRSTR,\
  40.                              (unsigned)strlen(ERRSTR));\
  41.                     exit(120); \
  42.                 }
  43.  
  44. void
  45. malloc_dump(fd)
  46.     int        fd;
  47. {
  48.     char              buffer[512];
  49.     void              exit();
  50.     int              i;
  51.     extern char        * malloc_data_end;
  52.     extern char        * malloc_data_start;
  53.     extern struct mlist     * malloc_end;
  54.     extern struct mlist      malloc_start;
  55.     struct mlist         * ptr;
  56.  
  57.     WRITEOUT(fd,"MALLOC CHAIN:\n",14);
  58.     WRITEOUT(fd,"-------------------- START ----------------\n",44);
  59.  
  60.     for(i=0; i < 80; i++)
  61.     {
  62.         buffer[i] = ' ';
  63.     }
  64.  
  65.     for(ptr = &malloc_start; ptr; ptr = ptr->next)
  66.     {
  67.         (void) tostring(buffer,       (int)ptr,         8,    B_HEX,    '0');
  68.         (void) tostring(buffer+9,  (int)ptr->next,   8,    B_HEX,    '0');
  69.         (void) tostring(buffer+18, (int)ptr->prev,   8,    B_HEX,    '0');
  70.         (void) tostring(buffer+27, (int)ptr->flag,  10,    B_HEX,    '0');
  71.         (void) tostring(buffer+38, (int)ptr->s.size, 8,    B_DEC,    ' ');
  72.         (void) tostring(buffer+47, (int)ptr->s.size, 8,    B_HEX,    '0');
  73.         (void) tostring(buffer+57, (int)ptr->data,   8,    B_HEX,    '0');
  74.         buffer[46] = '(';
  75.         buffer[55] = ')';
  76.         buffer[65] = '\n';
  77.         WRITEOUT(fd,buffer,66);
  78.     }
  79.     WRITEOUT(fd,"-------------------- DONE -----------------\n",44);
  80.  
  81.     WRITEOUT(fd,"Malloc start:      ",19);
  82.     (void) tostring(buffer, (int) &malloc_start, 8, B_HEX, '0');
  83.     buffer[8] = '\n';
  84.     WRITEOUT(fd,buffer,9);
  85.  
  86.     WRITEOUT(fd,"Malloc end:        ", 19);
  87.     (void) tostring(buffer, (int) malloc_end, 8, B_HEX, '0');
  88.     buffer[8] = '\n';
  89.     WRITEOUT(fd,buffer,9);
  90.  
  91.     WRITEOUT(fd,"Malloc data start: ", 19);
  92.     (void) tostring(buffer, (int) malloc_data_start, 8, B_HEX, '0');
  93.     buffer[8] = '\n';
  94.     WRITEOUT(fd,buffer,9);
  95.  
  96.     WRITEOUT(fd,"Malloc data end:   ", 19);
  97.     (void) tostring(buffer, (int) malloc_data_end, 8, B_HEX, '0');
  98.     buffer[8] = '\n';
  99.     WRITEOUT(fd,buffer,9);
  100.     
  101. } /* malloc_dump(... */
  102.  
  103.  
  104. /*
  105.  * $Log: dump.c,v $
  106.  * Revision 1.1  1992/01/24  03:29:01  dvadura
  107.  * dmake Version 3.8, Initial revision
  108.  *
  109.  * Revision 1.5  90/08/29  21:22:37  cpcahil
  110.  * miscellaneous lint fixes
  111.  * 
  112.  * Revision 1.4  90/05/11  00:13:08  cpcahil
  113.  * added copyright statment
  114.  * 
  115.  * Revision 1.3  90/02/24  21:50:07  cpcahil
  116.  * lots of lint fixes
  117.  * 
  118.  * Revision 1.2  90/02/24  17:27:48  cpcahil
  119.  * changed $header to $Id to remove full path from rcs id string
  120.  * 
  121.  * Revision 1.1  90/02/22  23:17:43  cpcahil
  122.  * Initial revision
  123.  * 
  124.  */
  125.